package com.sl.biz.modular.workflow.dao.service.impl;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sl.biz.modular.workflow.dao.domain.entity.WorkflowDO;
import com.sl.biz.modular.workflow.dao.domain.entity.WorkflowInstanceDO;
import com.sl.biz.modular.workflow.dao.mapper.WorkflowInstanceMapper;
import com.sl.biz.modular.workflow.dao.mapper.WorkflowMapper;
import com.sl.biz.modular.workflow.dao.service.WorkflowInstanceDaoService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@RequiredArgsConstructor
public class WorkflowInstanceDaoServiceImpl extends ServiceImpl<WorkflowInstanceMapper, WorkflowInstanceDO> implements WorkflowInstanceDaoService {
    @Override
    public Boolean updateStateById(String workflowInstanceId, String state) {
        LambdaUpdateWrapper<WorkflowInstanceDO> lambdaUpdateWrapper = new LambdaUpdateWrapper<>();
        lambdaUpdateWrapper.eq(WorkflowInstanceDO::getId, workflowInstanceId);
        lambdaUpdateWrapper.set(WorkflowInstanceDO::getStatus, state);
        return super.update(lambdaUpdateWrapper);
    }

    @Override
    public List<WorkflowInstanceDO> queryByCondition(WorkflowInstanceDO workflowInstanceDO) {
        LambdaQueryWrapper<WorkflowInstanceDO> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        lambdaQueryWrapper.eq(StrUtil.isNotBlank(workflowInstanceDO.getWorkflowId()), WorkflowInstanceDO::getWorkflowId, workflowInstanceDO.getWorkflowId());
        return super.list(lambdaQueryWrapper);
    }
}
